# -*- coding: utf-8 -*-
from datetime import timedelta

from jms.dim.dim_lmdm_sys_first_code import jms_dim__dim_lmdm_sys_first_code
from jms.ods.oms.yl_oms_oms_waybill__0300 import jms_ods__yl_oms_oms_waybill__0300
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
# from utils.operators.spark_sql_operator import SparkSqlOperator
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dwd__dwd_yl_oms_oms_waybill_incre_hi = SparkSqlOperator(
    task_id='jms_dwd__dwd_yl_oms_oms_waybill_incre_hi',
    task_concurrency=1,
    pool_slots=10,
    master='yarn',
    name='jms_dwd__dwd_yl_oms_oms_waybill_incre_hi_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/oms/dwd_yl_oms_oms_waybill_incre_hi/execute.sql',
    driver_memory='28G',
    driver_cores=12,
    executor_cores=8,
    executor_memory='12G',
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    num_executors=60,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 120,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '4G',  # 堆外内存
          'spark.sql.shuffle.partitions': 2400,
          'spark.shuffle.io.retryWait':'20',
          'spark.shuffle.memoryFraction': '0.8',
          'spark.shuffle.file.buffer':'64k',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=8'
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 91,  # 每天生成 60 个分区
              'hive.exec.max.dynamic.partitions.pernode': 91,  # 每天生成 60 个分区
              },
    yarn_queue='pro',
    #execution_timeout=timedelta(hours=2)
    #excel平均时长:10分14秒
    execution_timeout = timedelta(minutes=80),
)

jms_dwd__dwd_yl_oms_oms_waybill_incre_hi << [jms_ods__yl_oms_oms_waybill__0300, jms_dim__dim_lmdm_sys_first_code,jms_dwd__dwd_yl_oms_oms_waybill_incre_dt]
